package com.cloud.logger.zchain.spring.interceptor;

import com.cloud.logger.zchain.core.common.properties.ServerInfo;
import com.cloud.logger.zchain.core.zookeeper.LeaderElection;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 浙江卓锐科技股份有限公司 版权所有 © Copyright 2018<br>
 *
 * @Description: <br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/4/14 15:21 <br>
 * @Author: <a href="836327318@qq.com">吴昌益</a>
 */
@Aspect
@Component
public class MutexHandlerInterceptor{

    @Around("execution(* *(..)) && @annotation(com.cloud.logger.zchain.spring.annotation.Mutex)")
    public Object invoke(ProceedingJoinPoint pjp) throws Throwable {
        String leader = LeaderElection.getLeader();
        if(leader!=null && leader.equals(ServerInfo.scheduleNode))
            return pjp.proceed();
        else
            return false;
    }

}
